<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>微信用户管理</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link href="https://cdn.staticfile.org/font-awesome/5.11.2/css/all.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/m.css" >
	<script src="/static/0504/enum.js"></script>
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
</div>
<div id="searchbar">
<div class="maction">
		<a href="javascript:void(0)" id="btn4" class="easyui-linkbutton c6" data-options="plain:true">发送客服消息</a>
		<a href="javascript:void(0)" id="btn3" class="easyui-linkbutton" data-options="plain:true">同步指定用户数据</a>
</div>
<form id="searchForm" >
	ID:<input id="search-id" name="id" class="easyui-textbox" style="width:100px;">
	关注状态:<input id="search-subscribe" name="subscribe" class="easyui-combobox" style="width:100px;"
	data-options="editable:false,panelMaxHeight:300,panelHeight:'auto',
		icons: [{
			iconCls:'icon-clear',
			handler:function(e){
				$(e.data.target).combobox('clear');
			}
		}],
	    data:ENUM.subscribe">
	昵称:<input id="search-nickname" name="nickname" class="easyui-textbox" >
	性别:<input id="search-sex" name="sex"  style="width:90px;">
	省份:<input id="search-province" name="province" style="width:90px;" class="easyui-textbox" >
	城市:<input id="search-city" name="city" style="width:90px;" class="easyui-textbox" >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
</form>
</div>
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
<script src="/static/init.js"></script>
<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
<script src="/static/searchEdit.js"></script>
<script src="/static/0331/enum.js?v=0217"></script>
<script src="https://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script>
<script>
var options={
	page_id:222,
	grid_id:"gridList",
	sqlname:"grid_222_wx_user",
	showCheckbox:false,
	rownumbers:false,
	gridParam:{"order":"desc","sort":"subscribe_time"},
	column_formatter:{
		sex:function(value,row,index){
			return ENUM.getComoboxValue("sex",value);
		},
		subscribe_scene:function(value,row,index){
			return ENUM.getComoboxValue("subscribe_scene",value);
		},
		subscribe:function(value,row,index){
			return ENUM.getComoboxValue("subscribe",value);
		},
		subscribe_time:function(value,row,index){
			return moment.unix(value).format('YYYY-MM-DD HH:mm:ss');
		}
		
	},
	searchParamOperator:{
		nickname:"contain"
	},
};
var editRow=null;
//document ready
$(function(){
	grid1=new uniontrip.datagrid.searchEdit(options);
	//tab
	
	$('#removeButton').bind('click',function(){gridConfirm(grid1,"是否确认删除？",deleteSubmit);});//删除行绑定事件
	
	$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
	
    $('#btn3').bind('click',updateUserInfo);
    $('#btn4').bind('click',function(){
		gridSelectRow(grid1.grid,function(row){
			editRow=row;
			EditDialogModifyMchId.dialog('open');
		});
	});
    //初始化搜索框
    initsearch();
    EditDialogModifyMchId=$("<div/>").appendTo("body").dialog({
		title:"发送文本消息",
		cls:"m-dialog",
		width:'400px',
		height:windowHeight*0.8,
		href:'msg.html',
		modal:true,
		closed:true,
		//maximized:true,
		onClose:function(){
			console.log('onClose');
			
		},
		onBeforeClose:function(){//
			console.log('onBeforeClose');
			$("#modifyMchId-form").form('clear');
			//$("#smartwizard").data("smartWizard").options.anchorSettings.enableAllAnchors=false;
			//$('#smartwizard').smartWizard('reset');
		},
		 buttons: [{
			text:'保存',
			iconCls:'fas fa-save mbutton',
			handler:saveWelcomeMsg
		},{
			text:'取消',
			iconCls:'fas fa-times mbutton',
			handler:function(){
				EditDialogModifyMchId.dialog('close')
			}
		}],
		onBeforeOpen:function(){
			console.log('onBeforeOpen');
			if($(this).data("panel").isLoaded){
				
			}
		},
		onOpened:function(){
			console.log('onOpened');
			if(editRow){
	    		
				$("#modifyMchId-form").form('load',editRow);
	  			
			}else{
			}
			
		},
		onOpen:function(){//在onLoad之前执行
			console.log('onOpen');
			console.log($(this).panel('options'));
			//console.log();
			if($(this).data("panel").isLoaded){
				$(this).panel('options').onOpened();
			}
		},
		onBeforeLoad:function(){
			console.log('onBeforeLoad');
		},
		onLoad:function(){//只加载一次
			console.log('onLoad');
			//document.getElementById("id").fireEvent("click");
			$(this).panel('options').onOpened();
			//$('#lng').iCheck();
		},
	});
});


function saveWelcomeMsg(){
	if($("#modifyMchId-form").form('enableValidation').form('validate')){
		let data=$("#modifyMchId-form").serializeObject();
		data.appid=editRow.appid;
		data.openid=editRow.openid;
		$.post("/authenticated/wxuser/customerMsg",data,function(result){
			if(result.success){
				info( "保存成功！");
				EditDialogModifyMchId.dialog('close');
				grid1.load();
			}else{
				$.messager.alert("提示", "保存失败！<br>"+result.message);
			}
		});
	}
}
function updateUserInfo(){
	var selectRows=grid1.grid.datagrid('getSelections');
	if(selectRows.length>0){
		var selectRow=selectRows[0];
		$.post("/authenticated/wxuser/updateUserInfo",JSON.stringify({id:selectRow.id}),function(result){
			if(result.success){
				grid1.grid.datagrid('load');
				$.messager.alert("提示", "同步信息成功！");
			}else{
				$.messager.alert("提示", "同步信息失败！<br>"+result.message);
			}
		});
	}else{
		$.messager.alert("提示", "请选择一条数据！");
	}
}


/**
 * 初始化搜索条件
 */
function initsearch(){
	$('#search-sex').combobox({
		panelMaxHeight:300,
		panelHeight:'auto',
		editable:false,
		//valueField:'id',
		//textField:'text',
		icons: [{
			iconCls:'icon-clear',
			handler:function(e){
				$(e.data.target).combobox('clear');
			}
		}],
	    data:ENUM.sex
	});
}
</script>
</body>
</html>